package com.bwie.controller;

import com.bwie.pojo.TbGoods;
import com.bwie.service.TbGoodsService;
import com.bwie.utils.R;
import com.bwie.vo.PageInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("/goods/goods")
public class TbGoodsController {

    @Autowired
    TbGoodsService tbGoodsService;

    /***
     *@Description:创建索引
     * @return com.bwie.utils.R
     * @author 26440
     *@date 2024/6/17 10:32
     *
     */
    @PostMapping("/createIndex")
    public R createIndex() {
        return tbGoodsService.createIndex();
    }
    /***
     *@Description:Es商品列表
     * @param pageInfoVo
     * @return com.bwie.utils.R
     * @author 26440
     *@date 2024/6/17 10:43
     *
     */
    @PostMapping("/EsGoodsVoPageList")
    public R EsGoodsVoPageList(@RequestBody PageInfoVo pageInfoVo) {
        return tbGoodsService.EsGoodsVoPageList(pageInfoVo);
    }
    /***
     *@Description:openFeign调品牌下拉框
     * @return com.bwie.utils.R
     * @author 26440
     *@date 2024/6/17 11:14
     *
     */
    @PostMapping("/getBrandList")
    public R getBrandList() {
        return tbGoodsService.getBrandList();
    }
    /***
     *@Description:上传图片
     * @param file
     * @return com.bwie.utils.R
     * @author 26440
     *@date 2024/6/17 11:25
     *
     */
    @PostMapping("/upload")
    public R upload(@RequestPart("file")MultipartFile file) {
        return tbGoodsService.upload(file);
    }
    /***
     *@Description:添加商品
     * @param tbGoods
     * @return com.bwie.utils.R
     * @author 26440
     *@date 2024/6/17 11:29
     *
     */
    @PostMapping("/saveGoods")
    public R saveGoods(@RequestBody TbGoods tbGoods,@RequestHeader("token") String  token) {
        return tbGoodsService.saveGoods(tbGoods,token);
    }
    /***
     *@Description:购买商品
     * @param tbGoods
     * @param token
     * @return com.bwie.utils.R
     * @author 26440
     *@date 2024/6/17 12:52
     *
     */
    @PostMapping("/purchaseGoods")
    public R purchaseGoods(@RequestBody List<TbGoods> tbGoods,@RequestHeader("token") String token) {
        return tbGoodsService.purchaseGoods(tbGoods,token);
    }
    /***
     *@Description:订单列表
     * @param token
     * @return com.bwie.utils.R
     * @author 26440
     *@date 2024/6/17 12:54
     *
     */
    @PostMapping("/getOrderList")
    public R getOrderList(@RequestHeader("token") String token) {
        return tbGoodsService.getOrderList(token);
    }
    @PostMapping("uploadOss")
    public R uploadOss(@RequestPart("file") MultipartFile file) {
        return tbGoodsService.uploadOss(file);
    }
}
